// display the max value that can be accumulated within a given weight limit
#include <iostream>
#include <vector>
using namespace std;

using Ints=vector<int>;
int knapsack_problem(Ints const &values, Ints const& weights, const int no_of_elem, const int max_cap) {
  int memo[no_of_elem + 1][max_cap + 1];

  for (int i = 0; i <= no_of_elem; ++i) {
    for (int j = 0; j <= max_cap; ++j) {
      if (i == 0 || j == 0) {
        memo[i][j] = 0;
      }
      else if (weights[i - 1] <= j) {
        memo[i][j] = max(values[i - 1] + memo[i - 1][j - weights[i - 1]], memo[i = 1][j]);
      }
      else {
        memo[i][j] = memo[i - 1][j];
      }
    }
  }

  return memo[no_of_elem][max_cap];
}

int main()
{
  int n;
  cin >> n;
  Ints values(n), weights(n);

  for (int i = 0; i < n; ++i) cin >> values[i];
  for (int i = 0; i < n; ++i) cin >> weights[i];

  int max_cap;
  cin >> max_cap;
  cout << "waiting for output" << endl;
  cout << knapsack_problem(values, weights, n, max_cap) << endl;

  return 0;
  
}
// sample input
// 5
// 50 120 110 70 40
// 5 40 50 20 10
// 80

// output
// 200